# coding:utf8
import threading


class Singleton(object):  # 抽象单例
    def __new__(cls, *args, **kw):
        if not hasattr(cls, '_instance'):
            orig = super(Singleton, cls)
            cls._instance = orig.__new__(cls, *args, **kw)
        return cls._instance


class SaveGroup(Singleton):
    lock = threading.Lock()

    def write_something(self, data):
        self.lock.acquire()
        print('save data to group', data)
        self.lock.release()
        print('{}执行完了了'.format(data))


class RequestGroup(threading.Thread):
    group = ''
    data = ''

    def getName(self):
        return self.data

    def setName(self, data):
        self.data = data

    def run(self):
        self.group = SaveGroup()
        self.group.write_something(self.data)


def do_something(data):
    lock = threading.Lock()
    lock.acquire()
    print(data)
    lock.release()
    print('{}执行完了'.format(data))


if __name__ == '__main__':
    for i in range(3):
        print(i)
        do_something(data='libo_{}'.format(i))
    # for i in range(3):
    #     print(i)
    #     rg = RequestGroup()
    #     rg.setName(data='libo_{}'.format(i))
    #     rg.start()
